<!DOCTYPE html>
<html lang="en">
<#assign title = "登录">
<#include "/element-ui-tpls/head.html"/>
<body>
<div id="app" v-cloak>
    <div style="width:1600px; margin: 40px auto;">
        <el-row>
            <el-col :span="12">
                <img src="/img/login.jpeg">
            </el-col>
            <el-col :span="12">
                <div style="width:500px; margin-top: 100px">
                    <h1 style="text-align: center; margin-left: 100px;">OPS 系统</h1>
                    <el-form :model="form" ref="form" :rules="rules" label-width="100px">
                        <el-form-item prop="account">
                            <el-input v-model="form.account" autocomplete="off" placeholder="账号"></el-input>
                        </el-form-item>
                        <el-form-item prop="pwd">
                            <el-input v-model="form.pwd" autocomplete="off" placeholder="密码"></el-input>
                        </el-form-item>
                        <el-form-item>
                            <el-button style="width: 400px;" type="primary" @click="doLogin">登录</el-button>
                        </el-form-item>
                    </el-form>
                </div>
            </el-col>
        </el-row>
    </div>
</div>

<#include "/element-ui-tpls/script.html"/>
<script>
    new Vue({
        el: '#app',
        data: {
            form: {
                account: '',
                pwd: '',
            },
            rules: {
                account: [
                    {required: true, message: '请输入账号', trigger: 'blur'},
                ],
                pwd: [
                    {required: true, message: '请输入密码', trigger: 'blur'}
                ],
            }
        },
        methods: {
            doLogin: function() {
                var vm = this;
                this.$refs['form'].validate(function(valid) {
                    if (valid) {
                        axios.post('/login', vm.form)
                            .then(function (data) {
                                location.href = "/";
                            });
                    } else {
                        return false;
                    }
                });
            }
        }
    });
</script>
</body>
</html>